<?php
/* @var $this AlbumController */
/* @var $model Album */
/* @var $form CActiveForm */
?>

<div class="row-fluid">
    <div class="span12 box">
        <div class="box-header blue-background">
            <div class="title">
                <div class="icon-edit"></div>
                Form Album
            </div>
            <div class="actions">
<!--                <a href="#" class="btn box-remove btn-mini btn-link"><i class="icon-remove"></i>
                </a>-->
                <a href="#" class="btn box-collapse btn-mini btn-link"><i></i>
                </a>
            </div>
        </div>
        <div class="box-content">
            <?php
            $form = $this->beginWidget('CActiveForm', array(
                'id'=>'album-form',
                // Please note: When you enable ajax validation, make sure the corresponding
                // controller action is handling ajax validation correctly.
                // There is a call to performAjaxValidation() commented in generated controller code.
                // See class documentation of CActiveForm for details on this.
                'enableAjaxValidation' => false,
                'htmlOptions' => array(
                    'class' => 'form form-horizontal',
            		'enctype' => 'multipart/form-data',
                )
            ));
            ?>
            <?php echo $form->errorSummary($model); ?>
            <div class="control-group">                    
                <?php echo $form->labelEx($model, 'name', array('class' => 'control-label')); ?>
                <div class="controls">
                    <?php echo $form->textField($model, 'name', array('size' => 60, 'maxlength' => 100)); ?>
                    <?php echo $form->error($model, 'name'); ?>
                </div>
            </div>
            <div class="control-group">
                <?php echo $form->labelEx($model, 'description', array('class' => 'control-label')); ?>
                <div class="controls">
                    <?php echo $form->textArea($model, 'description', array('size' => 60, 'maxlength' => 255)); ?>
                    <?php echo $form->error($model, 'description'); ?>
                </div>
            </div>
            
            <div class="control-group">
                <?php echo $form->labelEx($model, 'gallery_id', array('class' => 'control-label')); ?>
                <div class="controls">
                	<?php //echo $form->dropDownList($model, 'gallery_id', CHtml::listData(Gallery::model()->findAll('id'), 'id', 'name'), array('empty'=>'--Select Gallery--')); ?>
                	<?php echo $form->dropDownList($model, 'gallery_id', CHtml::listData(Gallery::model()->findAll('id'), 'id', 'name')); ?> 
                    <?php echo $form->error($model, 'description'); ?>
                </div>
            </div>
            
            <div class="control-group">
                <?php echo $form->labelEx($model, 'url', array('class' => 'control-label')); ?>
                <div class="controls">
                    <?php echo $form->fileField($model, 'url', array('size' => 60, 'maxlength' => 255, 'name' => 'url[]', 'onchange' => 'readURL(this)')); ?>
                    <?php echo $form->error($model, 'url'); ?>
                    <div id="showimg" style="width: 200px; height: 40px; display: block;"></div>
                </div>
            </div>
            
            <div class="photos control-group">
            	<?php if (!($model->isNewRecord) && $model->url!='') : ?>
          			<?php 
                 	echo '<div class="controls">';
                 	echo '<div id="showimg" style="width: 200px; height: 40px; display: block;">';
                	echo '<img id="album_image"  src="'.Yii::app()->request->baseUrl.$model->url.'" width="80px" style="margin-top:-45px;"/>';
                	echo '</div>';
                   	echo '</div>';
              	?>
             	<?php endif; ?>

          	</div>
          	
            <div class="form-actions">
                <button class="btn btn-primary" type="submit">
                   
                    <i class="icon-save"></i>
                    <?php echo $model->isNewRecord ? 'Create' : 'Save' ?>
                </button>
                <a href="<?php echo $this->createUrl('/album/admin'); ?>">
                	<button class="btn" type="button">Cancel</button>
                </a>
            </div>

            <?php $this->endWidget(); ?>
        </div>
    </div>
</div>

<script type="text/javascript">
function readURL(me) {
	$('.file-input-name').html('');
    if (me.files && me.files[0]) {
        var reader = new FileReader();

        reader.onload = function(e) {
			var checkImage = $('.photos').find($('#album_image')).length;
            if (checkImage) {
            	$('#album_image').attr('src', e.target.result).width(80).css('margin-top', '-45px');
            } else {
            	var htmlPattern = '<img id="album_image" width="80px" src="' + e.target.result + '" />';
                $('#showimg').html(htmlPattern).css('padding', '18px 0 20px 0');
            }
        };

        reader.readAsDataURL(me.files[0]);
    }
}
</script>
